import { ref } from "vue";
import { defineStore } from "pinia";

export const useTrafficStore = defineStore("traffic", () => {
  //路况信息列表
  const getTrafficReports = () => {
    const trafficReports = ref([]);
    if (localStorage.getItem("trafficReports")) {
      trafficReports.value = JSON.parse(localStorage.getItem("trafficReports"));
    }
    return trafficReports;
  };
  const trafficReports = getTrafficReports();
  /* 添加路况信息 */
  const addTrafficReport = (val) => {
    trafficReports.value.push(val);
    localStorage.setItem(
      "trafficReports",
      JSON.stringify(trafficReports.value)
    );
  };
  //公告信息
  const announcement = ref({});
  if (localStorage.getItem("Announcement")) {
    announcement.value = JSON.parse(localStorage.getItem("Announcement"));
  }
  //添加公告信息
  const addAnnouncement = (val) => {
    announcement.value = '';
    announcement.value = val;
    localStorage.setItem("Announcement", JSON.stringify(announcement.value));
  };

  //mapgis数据放在仓库中
  const docLayer = ref(null);
  //添加doclayer
  docLayer.value = new Zondy.Map.Doc("", "guanggu", {
    ip: "localhost",
    port: 6163 /*  */,
  });
  return { trafficReports, announcement, docLayer, addTrafficReport, addAnnouncement };
});
